﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Web.Views.Common
{
    public partial class Index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        public static string GetPastTime(string caption)
        {
           //string caption = "2009-05-05 13:27:20";
            DateTime d1 = DateTime.Parse(caption);

            DateTime d2 = DateTime.Parse(DateTime.Now.ToLongTimeString());

            System.TimeSpan ND = d2 - d1;

            int n = ND.Days;   //天数差

            int hn = ND.Hours; //小时差
            int m = ND.Minutes;// 分钟差

            string res;


            if (n == 0 && hn == 0)
            {
                res = m.ToString() + "分钟前";
            }
            else if (n == 0 && hn > 0)
            {
                res = hn.ToString() + "时" + m.ToString() + "分钟前";
            }
            else
            {
                res = n.ToString() + "天" + hn.ToString() + "时" + m.ToString() + "分钟前";
            }
            return res;
        }
    
    }
}
